/**
 * 
 */
package com.cipe.cmrs.validator;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;

import com.cipe.cmrs.model.Donor;
import com.cipe.cmrs.service.DonorService;

/**
 * @author Incepio
 * 
 */
@Component
public class DonorValidator {
	@Autowired
	private DonorService donorService;

	public void validate(Errors errors, Donor donor) {
		if (StringUtils.isNotBlank(donor.getDonorName()) && donorService.donorNameExists(donor.getDonorName(), donor.getId())) {
			errors.reject("exists.donorname", "Donor name already exists.");
		}
	}
}
